import React, { Component } from 'react'
import axios from 'axios'
import {Speed} from '../../types/home.d'


interface Iprops{
    match:any,
    history:any
}

interface Istate{
    speedList:Speed[]
}

export default class Choose extends Component<Iprops,Istate> {
    state = {
        speedList:[]
    }
    componentDidMount(){
        console.log(this.props.match.params.id)
        axios.get('/api/speed',{data:{id:this.props.match.params.id}}).then(res =>{
            console.log(res.data.data)
            if(res.data.code === 10000){
                this.setState({
                    speedList:res.data.data
                })
            }
        })
    }
    render() {
        let {speedList} = this.state;
        return (
            <div>
                <ul>
                    {speedList && speedList.map((item:Speed) => <li onClick={() => {
                        this.choose(item.spe_name)
                    }}>{item.spe_name}</li>)}
                </ul>
            </div>
        )
    }

    choose = (spe_name:string) => {
        this.props.history.push({pathname:'/public',state:{spe_name}})
    }
}
